package la.iok.hzsvn.lewin.movie.controller;

import la.iok.hzsvn.lewin.movie.core.RoleEnum;
import la.iok.hzsvn.lewin.movie.core.Token;
import la.iok.hzsvn.lewin.movie.core.exception.ErrorCode;
import la.iok.hzsvn.lewin.movie.entity.InnerTestMovie;
import la.iok.hzsvn.lewin.movie.model.MovieInnerTestVo;
import la.iok.hzsvn.lewin.movie.service.InnerTestMovieService;
import la.iok.hzsvn.lewin.mybatis.model.PageVo;
import la.iok.hzsvn.share.annotations.Nullable;
import la.iok.hzsvn.share.response.OperatorResponse;
import la.iok.hzsvn.share.response.OperatorResponses;
import la.iok.hzsvn.share.response.SingleDataResponse;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("innerTestMovies")
public class InnerTestMovieController {
    private final InnerTestMovieService innerTestMovieService;

    public InnerTestMovieController(InnerTestMovieService innerTestMovieService) {
        this.innerTestMovieService = innerTestMovieService;
    }

    /**
     * 剧本内测配置
     * @param token 操作用户
     * @param entity 参数,只需要剧本id和房间id
     * @return 操作结果
     */
    @PostMapping
    public OperatorResponse save(@RequestHeader Token token, @RequestBody InnerTestMovie entity){
        token.validAnyAuthority(RoleEnum.Admin);
        innerTestMovieService.save(entity.getMovieId(),entity.getRoomId());
        return OperatorResponses.success();
    }

    /**
     * 删除记录
     * @param token 操作用户
     * @param id 记录id
     * @return 操作结果
     */
    @DeleteMapping("{id}")
    public OperatorResponse delete(@RequestHeader Token token,@PathVariable Long id){
        token.validAnyAuthority(RoleEnum.Admin);
        innerTestMovieService.delete(id);
        return OperatorResponses.success();
    }

    @GetMapping
    public SingleDataResponse<PageVo<MovieInnerTestVo>> page(
            @RequestHeader Token token,int page, int limit,
            @Nullable Long movieId, @Nullable Long orgUnitId, @Nullable Long roomId){
        token.validAnyAuthority(RoleEnum.Admin);
        return new SingleDataResponse<>(innerTestMovieService.page(page,limit,movieId,orgUnitId,roomId));
    }
}
